package com.example.receiptmanage.repository;

import com.example.receiptmanage.entity.Receipts;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

@Repository
public interface ReceiptRepository extends JpaRepository<Receipts, Long> {
    List<Receipts> findByUserIdOrderByReceiptDateDesc(Long userId);

    @Query("SELECT r FROM Receipts r WHERE r.userId = :userId ORDER BY r.receiptDate DESC")
    List<Receipts> findReceiptsByUserIdOrderByReceiptDateDesc(@Param("userId") Long userId);

    List<Receipts> findByUserIdAndReceiptDateBetween(
            Long userId,
            LocalDate startDate,
            LocalDate endDate
    );

    Optional<Receipts> findByReceiptIdAndUserId(Long receiptId, Long userId);
}